package com.power.controller;

import com.alibaba.fastjson.JSON;
import com.power.ov.ResultData;
import com.power.ov.ResultDataTable;
import com.power.service.LineService;
import com.power.service.impl.LineServiceimpl;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.sql.SQLException;

/**
 * Created with IntelliJ IDEA.
 * User: 李辽
 * Date: 2020/10/08 11:04
 * Description:
 * Version: V1.0
 */
@WebServlet("/deleteLine.do")
public class DeleteLine extends HttpServlet {
    @Override
    protected void service(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        String line_id = request.getParameter("line_id");
        LineService lineService = new LineServiceimpl();

        response.setContentType("application/json;charset=utf-8");
        ResultDataTable resultData = new ResultDataTable();

        try {
            int result = lineService.DeletLine(line_id);
            resultData.setCode(200);
            resultData.setMessage("删除成功");
        } catch (SQLException e) {
            e.printStackTrace();
            resultData.setCode(500);
            resultData.setMessage("删除失败，请重试！！");
        }
        response.getWriter().write(JSON.toJSONString(resultData));
        response.getWriter().flush();
        response.getWriter().close();
    }
}
